<div class="modal fade " id="maintainProductModal"  role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">产品维护</h3>
            </div>
            <form class="form-horizontal" role="form" id="maintainProductForm"  method="post"  enctype="multipart/form-data">
                <div class="box-body">
                    <div class="form-group">
                        <input id="productId" name="productId" type="text" disabled="disabled" class="form-control" style="display:none;">

                        <label class="col-sm-2 control-label" for="productNameLabel">产品名称</label>
                        <div class="col-sm-4">
                            <input id="productName" name="productName" type="text" class="form-control" maxlength="100">
                        </div>
                        
                         <label class="col-sm-2 control-label" for="productZTBHLabel">账户号</label>
                        <div class="col-sm-4">
                            <input id="productZTBH" name="productZTBH" type="text" class="form-control"
                                   maxlength="4" onblur= "if( /[^\d]/g.test(this.value)){toastr['error']('账户号只能输入4位整数', '提示');}">

                        </div>                        
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="productCodeLabel">产品代码</label>
                        <div class="col-sm-4">
                            <input id="productCode" name="productCode" type="text" class="form-control"
                                   minlength="6" maxlength="6">
                        </div>
                        
                        <label class="col-sm-2 control-label" for="productNameLaEbel">基准ID</label>
                        <div class="col-sm-4">
                            <input id="benchmarkId" name="benchmarkId" type="text" class="form-control" maxlength="10">
                        </div>                       
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for=tgEmailLabel">托管行邮箱</label>
                        <div class="col-sm-4">
                            <input id="tgEmail" name="tgEmail" type="text" class="form-control">
                        </div>
                        <label class="col-sm-2 control-label" for="tgFaxLabel">托管行传真</label>
                        <div class="col-sm-4">
                            <input id="tgFax" name="tgFax" type="text" class="form-control">

                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="productTypeLabel">产品类型</label>
                        <div class="col-sm-4">
                            <select id="productType" name="productType" class=" form-control select2" style="width: 100%">
                                <#if typeListVos??>
                                    <#list typeListVos as vo  >
                                    <option value="${vo.keyValue?if_exists}">${vo.caption?if_exists}</option>
                                    </#list>
                                </#if>
                            </select>
                        </div>
                        <label class="col-sm-2 control-label" for="productStatusLabel">产品状态</label>
                        <div class="col-sm-4">
                            <select id="productStatus" name="productStatus" class="form-control">
                                <option value="0">待发行</option>
                                <option value="1">存续</option>
                                <option value="2">已清盘</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="produ4ctTypeLabel">收益类型</label>
                        <div class="col-sm-4">
                             <select id="revenueType" name="revenueType" class="form-control">
                                <option value="相对收益">相对收益</option>
                                <option value="绝对收益">绝对收益</option>                              
                            </select>
                        </div>
                        <label class="col-sm-2 control-label" for="prod6uctStatusLabel">账户类型</label>
                        <div class="col-sm-4">
                            <select id="accountType" name="accountType" class="form-control">
                                <option value="权益">权益</option>
                                <option value="纯债">纯债</option>
                                <option value="混合">混合</option>
                                <option value="货币">货币</option>
                            </select>
                        </div>
                    </div>
                     <div class="form-group">
                        <label class="col-sm-2 control-label" for=tgEmailLal">主责投资经理账号</label>
                        <div class="col-sm-4">
                            <input id="manager" name="manager" type="text" class="form-control">
                        </div>  
                         <label class="col-sm-2 control-label" for="prod6uctStatusLabel">是否评分</label>
                        <div class="col-sm-4">
                            <select id="isScore" name="isScore" class="form-control">
                                <option value="Y">Y</option>
                                <option value="N">N</option>
                               
                            </select>
                        </div>                     
                    </div>
                </div>
                <div class="box-footer">
                    <button type="button" class="btn btn-danger pull-left" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary pull-right" onclick="saveProduct()">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
<#include "../public/js.ftl" >
<#include "../public/css.ftl">
<script src="/js/common.js"></script>
<script>
    function maintainProductInit() {
        //初始化产品维护画面
        $("#productId").val("");
        $("#productName").val("");
        $("#productCode").val("");
        $("#productZTBH").val("");
        $("#productType").val("1");
        $("#productStatus").val("1");
        
        $("#tgEmail").val("");
        $("#tgFax").val("");
        $("#manager").val("");
        
        $("#benchmarkId").val("");
        $("#revenueType").val("0");
        $("#accountType").val("0");
        $("#isScore").val("Y");
        
    }

    function modifyProductInit(data) {
        //查询数据设置到修改画面对应栏位
        $("#productId").val(data.productId);
        $("#productName").val(data.productName);
        $("#productName").attr("disabled","disabled");
        $("#productCode").val(data.productCode);
        $("#productCode").attr("disabled","disabled");
        $("#productZTBH").val(data.productZtbh);
        $("#productZTBH").attr("disabled","disabled");
        $("#productType").val(data.productType);
        $("#productStatus").val(data.productStatus);
        $("#tgEmail").val(data.tgEmail);
        $("#tgFax").val(data.tgFax);
        $("#manager").val(data.manager);
        
        $("#benchmarkId").val(data.benchmarkId);
        $("#revenueType").val(data.revenueType);
        $("#accountType").val(data.accountType);
        
        $("#isScore").val(data.isScore);
    }

    function saveProduct(){
        //产品ID
        var productId = $("#productId").val();

        //产品名称
        var productName = $("#productName").val();
        //去除空格
        productName = strTrim(productName);

        if (productName == "") {
            toastr['error']("产品名称不能为空", '异常');
            return;
        }

        //检查产品名称长度不能超过100个字符
        var length = strlen(productName);
        if (length > 100) {
            toastr['error']("产品名称长度不能超过100个字符", '异常');
            return;
        }

        //产品代码
        var productCode = $("#productCode").val();
        //账户号
        var productZtbh = $("#productZTBH").val();
        if (productZtbh != "") {
            if( /[^\d]/g.test(productZtbh)){
                toastr['error']("账户号只能输入整数", '提示');
                return;
            }
            //检查账户号合法位数是否为4位整数
            if(productZtbh < 1000 || productZtbh > 9999){
                toastr['error']("账户号只能输入4位整数", '提示');
                return;
            }
        }

        //产品类型
        var productType = $('#productType option:selected').val();
        //产品状态
        var productStatus = $('#productStatus option:selected').val();
        
        var tgEmail = $("#tgEmail").val();
          
        var tgFax = $("#tgFax").val();
        
        var manager = $("#manager").val();
        
        
        var benchmarkId = $("#benchmarkId").val();
        
        var revenueType = $('#revenueType option:selected').val();
       
        var accountType = $('#accountType option:selected').val();
        
        var isScore = $('#isScore option:selected').val();

        var data = {
            productId : productId,
            productName : productName,
            productCode : productCode,
            productZtbh : productZtbh,
            productType : productType,
            productStatus : productStatus,
            tgEmail : tgEmail,
            tgFax : tgFax,
            manager : manager,
            
            benchmarkId : benchmarkId,
            revenueType : revenueType,
            accountType : accountType,
            isScore : isScore
        };

        var url = "/productmanager/maintainProduct";

        postReq(url, data, function (result) {
            if (result.success) {
                maintainProductInit();
                $("#productTable").bootstrapTable("refresh");
                $("#maintainProductModal").modal("hide");
                toastr['success']('产品保存成功', '提示');
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }
</script>
